const app = getApp();
const publicFun = require('/utils/public.js');
import { setGenerateCertificate } from '/utils/request'
Page({
  data: {
    inputVal: '',
    clickAbled: true,
    generateState: 1,
  },
  onLoad(options) {
    this.setData({
      systemInfo: app.globalData.systemInfo,
      huodongid: options.huodongid,
      name: options.name
    })
    my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff',
    });
  },
  getInput(e) {
    this.setData({
      inputVal: e.detail.value,
      clickAbled: false
    })
  },
  async setGenerate() {
    my.showLoading();
    try {
      let params = {
        userid: app.globalData.userid,
        name: this.data.inputVal,
        type: this.data.huodongid
      }
      const res = await setGenerateCertificate(params);
      my.hideLoading();
      if(res.S == 1){
        this.setData({generateState: 2, imgUrl: res.Url})
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败');
      }
    } catch (e) {
      my.hideLoading();
      publicFun.showToast('失败，请稍后再试')
    }
  },
  previewImage() { //查看大图
    let arr = [this.data.imgUrl];
    my.previewImage({
      current: 0,
      enablesavephoto: true,
      urls: arr,
      // enableShowPhotoDownload: true
    });
  },
  downloadClick() {
    my.saveImageToPhotosAlbum ({
      filePath: this.data.imgUrl
    });
  },
});
